import BaseModel from './baseModel'
import { ImageFill } from '../utils/filters'
import { get } from '../ajax/axios'
import { Api } from '../ajax/api'

/**
 * 我的模型
 */
class MeModel extends BaseModel {


  home_icon: string = ''
  home_title: string = ''
  home_jianli: string = ''
  abouts: string = ''
  aboutArr: Array<string> = []
  expertise: string = ''
  expertiseArr: Array<string> = []
  iosNum = 0
  nodeNum = 0
  webNum = 0
  xcxNum = 0
  javaNum = 0
  iosShow = ''
  webShow = ''
  nodeShow = ''
  xcxShow = ''
  javaShow = ''
  iosShowArr: Array<string> = []
  webShowArr: Array<string> = []
  nodeShowArr: Array<string> = []
  xcxShowArr: Array<string> = []
  javaShowArr: Array<string> = []
  experience_show = ''
  experience_show_arr: Array<string> = []
  works_show = ''
  works_show_arr: Array<string> = []

  /* ----- 获取指定图片大小 -------*/
  /**
   * PC端首页图片
   * @returns {*|string}
   */
  get pcMeHomeIconUrl() {
    return ImageFill(this.home_icon, 150, 150)
  }

  public setDataWithJson(json: object) {
    super.setDataWithJson(json)
    this.aboutArr = this.abouts.split('\n')
    this.expertiseArr = this.expertise.split('\n')
    this.iosShowArr = this.iosShow.split('\n')
    this.webShowArr = this.webShow.split('\n')
    this.nodeShowArr = this.nodeShow.split('\n')
    this.xcxShowArr = this.xcxShow.split('\n')
    this.javaShowArr = this.javaShow.split('\n')
    this.experience_show_arr = this.experience_show.split('\n')
    this.works_show_arr = this.experience_show.split('\n')
  }

  /**
   * 获取数据
   */
  static async getData(): Promise<MeModel> {
    const data = await get(Api.me.detail)
    const model = new MeModel()
    model.setDataWithJson(data)
    return model
  }
}

export default MeModel
